package gases.as3.librarys.compnents.ui.control.datagrid
{
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import gases.as3.librarys.compnents.ui.GUIComepments;
	
	public class GridCell extends GUIComepments
	{
		/**
		 *背景颜色初始值 
		 */		
		public static const BG_INIT_COLOR:uint = 0x03dcb1;
		/**
		 *鼠标移上去改变颜色 
		 */		
		public static const BG_OVER_COLOR:uint = 0xDD00DD;
		/**
		 *鼠标点击改变颜色 
		 */		
		public static const BG_CLICK_COLOR:uint = 0xFFDD00;
		
		/**
		 *初始化 显示高度
		 */		
		public static const TEXT_HEIGHT:Number = 18;
		/**
		 *背景textField 
		 */		
		public var txtBg:TextField;
		/**
		 *数据textField 
		 */		
		public var txtData:TextField;
		/**
		 *单元格子 
		 * @param width
		 * @param height
		 * 
		 */		
		public function GridCell(width:Number,height:Number)
		{
			_width =	 width;
			_height =	 height;
			super();
		}
		
		override protected function initialization():void
		{
			txtBg = new TextField();
			txtBg.width = 	_width;
			txtBg.height =  _height;
			txtBg.borderColor = 0x000000;
			txtBg.border = true;
			txtBg.background = true;
			txtBg.backgroundColor = BG_INIT_COLOR;
			
			txtData = new TextField();
			txtData.width = _width;
			txtData.autoSize = TextFieldAutoSize.CENTER;
			if(_height > TEXT_HEIGHT )
			{
				txtData.height = TEXT_HEIGHT;
				txtData.y =  (_height - TEXT_HEIGHT)/2;
			}
			else
			{
				txtData.height = _height;
			}
			txtData.mouseEnabled = false;
			this.addChildAt(txtBg,0);
			this.addChild(txtData);
		}
		
		/**
		 *设置单元格数值 
		 * @param value
		 * @param color
		 * 
		 */		
		public function setDataValue(value:String,color:uint = 0x000000):void
		{
			txtData.text = value;
			txtData.textColor = color;
		}
		
		
		override public function dispose():void
		{
			this.removeChild(txtBg);
			txtBg = null;
			this.removeChild(txtData);
			txtData = null;
			super.dispose();
		}
		
		public function cellOver():void
		{
			txtBg.background = true;
			txtBg.backgroundColor = BG_OVER_COLOR;
		}
		
		public function cellOut():void
		{
			txtBg.background = true;
			txtBg.backgroundColor = BG_INIT_COLOR;
		}
		
		public function cellClick():void
		{
			txtBg.background = true;
			txtBg.backgroundColor = BG_CLICK_COLOR;
		}
		
		private var _width:Number ;
		private var _height:Number ;
	}
}